﻿using UnityEngine;
using strange.extensions.command.impl;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.context.api;

public class RequestScoreCommand : EventCommand 
{
	[Inject]
	public IScoreService scoreService{ get; set;}
	[Inject]
	public ScoreModel scoreModel{ get; set;}
	public override void Execute ()
	{
		Retain ();
		
		scoreService.dispachter.AddListener (ServiceEvent.RequestScore, OnComplete);

		scoreService.RequestScore ("http://www.liumj.com/set20");


	}

	public void OnComplete(IEvent evt)
	{
		Debug.Log (evt.data);

		scoreService.dispachter.RemoveListener (ServiceEvent.RequestScore,OnComplete);
		scoreModel.Score = (int)evt.data;
		dispatcher.Dispatch (MediatorEvent.ScoreChange,evt);

		Release ();
	}
}
